<?php
$tplname = "blogentry.tpl";

$query = "SELECT id, title, description FROM blogEntries WHERE alias = '$subsection'";

$res1 = $db->runQuery($query);
$row1 = $db->getRow($res1);
$entryId = $row1["id"];
$pagetitle = utf8_encode($row1["title"]);
$content->assign("description", stripslashes(utf8_encode($row1["description"])));
$content->assign("entryid", $entryId);
$content->assign("comments", array());
$content->assign("nocomments", "");

// Barra de compartir
$content->assign("sharelinks", $content->generateShareLinks(PAGE_URL));

$where = "entryId = '$entryId' AND status = 1";
$query = "SELECT id FROM blogComments WHERE $where";
$res30 = $db->runQuery($query);
$numComments = $db->getRowCount($res30);
if ($numComments > 0) {

	$page = isset($_GET["page"]) ? $_GET["page"] : 1;
	$offset = MAX_COMMENTS_ON_BLOG * ($page - 1);
	$query = "SELECT created, author, content, picture FROM blogComments WHERE $where ORDER BY created DESC LIMIT $offset, ".MAX_COMMENTS_ON_BLOG;
	$res20 = $db->runQuery($query);
	$comments = array();
	while ($row20 = $db->getRow($res20)) {
		$pictureName = $row20["picture"];
		if (!file_exists(UPLOADS_DIR.$pictureName)) $pictureName = "";
		$pictureUrl = (strlen($pictureName) > 0 ? "/uploads/".utf8_encode($pictureName) : "");
		$pictureThumb = (strlen($pictureName) > 0 ? BASE_URL."thumb.php?src=".$pictureUrl."&w=100" : "");
		$comments[] = array(
			"author" => utf8_encode($row20["author"]),
			"created" => $row20["created"],
			"content" => utf8_encode($row20["content"]),
			"picturename" => $pictureName,
			"pictureurl" => $pictureUrl,
			"picturethumb" => $pictureThumb
		);
	}
	$content->assign("comments", $comments);

	$maxPages = ceil($numComments / MAX_COMMENTS_ON_BLOG);
	if ($maxPages > 1) {
		//$content->assign("pagination", $content->generatePaginationLinks($section, $subsection, $numComments, MAX_COMMENTS_ON_BLOG, $lang)); 
	}

} else {
	$content->assign("nocomments", $content->langmsg["nocomments"]);
}

/*
// Pintamos los comentarios
$page = isset($_GET["page"]) ? $_GET["page"] : 1;
$offset = MAX_COMMENTS_ON_BLOG * ($page - 1) + 1;
$query = "SELECT created, author, content, picture FROM blogComments WHERE entryId = '$entryId' AND status = 1 ORDER BY created DESC LIMIT $offset, ".MAX_COMMENTS_ON_BLOG;

$res20 = $db->runQuery($query);
$numComments = $db->getRowCount($res20);
if ($numComments > 0) {
	$comments = array();
	while ($row20 = $db->getRow($res20)) {
		$pictureName = $row20["picture"];
		if (!file_exists(UPLOADS_DIR.$pictureName)) $pictureName = "";
		$pictureUrl = (strlen($pictureName) > 0 ? "/uploads/".utf8_encode($pictureName) : "");
		$pictureThumb = (strlen($pictureName) > 0 ? BASE_URL."phpThumb.php?src=".$pictureUrl."&w=100" : "");
		$comments[] = array(
			"author" => utf8_encode($row20["author"]),
			"created" => $row20["created"],
			"content" => utf8_encode($row20["content"]),
			"picturename" => $pictureName,
			"pictureurl" => $pictureUrl,
			"picturethumb" => $pictureThumb
		);
	}
	$content->assign("comments", $comments);
} else {
	$content->assign("nocomments", $content->langmsg["nocomments"]);
}
*/

$content->assign("formaction", BASE_URL.$lang."/process-newcomment-form/");
$content->assign("numcomments", $numComments);
$varNames = array("commentslabel", "sendyourcommentlabel", "namelabel", "commentlabel", "captchalabel", "captchatext", "regeneratecaptcha", "sendlabel", "picturelabel");
$content->multipleAssign($varNames);
?>
